#ifndef __CURSOR_H__
#define __CURSOR_H__

#include "../VT100/VT100.hpp"
#include "../checkerBoard/CheckerBoard.hpp"
#include "../coord/Coord.hpp"
#include <cstdio>
#include <iostream>
#include <ostream>

/**
 * @brief 光标
 *
 */
class Cursor : public Coord {
private:
public:
  Cursor() {
    setDisplayPositionX(((CHESS_BOARD_COLUMNS / 2) * CHESS_BOARD_SKIP_X) +
                        CHESS_BOARD_MIN_X);
    setDisplayPositionY(((CHESS_BOARD_ROWS / 2) * CHESS_BOARD_SKIP_Y) +
                        CHESS_BOARD_MIN_Y);

    cursorShow();
  }

  ~Cursor() {}

  /**
   * @brief 光标上移
   *
   */
  void cursorUP(void) {
    unsigned int y = getDisplayPositionY();
    if (y - CHESS_BOARD_SKIP_Y >= CHESS_BOARD_MIN_Y) {
      y -= CHESS_BOARD_SKIP_Y;
    }
    setDisplayPositionY(y);
    cursorShow();
  }

  /**
   * @brief 光标下移
   *
   */
  void cursorDown(void) {
    unsigned int y = getDisplayPositionY();
    if (y + CHESS_BOARD_SKIP_Y <= CHESS_BOARD_MAX_Y) {
      y += CHESS_BOARD_SKIP_Y;
    }
    setDisplayPositionY(y);
    cursorShow();
  }

  /**
   * @brief 光标左移
   *
   */
  void cursorLeft(void) {
    unsigned int x = getDisplayPositionX();
    if (x - CHESS_BOARD_SKIP_X >= CHESS_BOARD_MIN_X) {
      x -= CHESS_BOARD_SKIP_X;
    }
    setDisplayPositionX(x);
    cursorShow();
  }

  /**
   * @brief 光标右移
   *
   */
  void cursorRight(void) {
    unsigned int x = getDisplayPositionX();
    if (x + CHESS_BOARD_SKIP_X <= CHESS_BOARD_MAX_X) {
      x += CHESS_BOARD_SKIP_X;
    }
    setDisplayPositionX(x);
    cursorShow();
  }

  /**
   * @brief 显示光标
   *
   */
  void cursorShow(void) {
    VT100::VT100SetTheCursor(getDisplayPositionX() + 1, getDisplayPositionY());
  }
};

#endif // __CURSOR_H__